This sample demonstrates how to use OTTransferProviderOwnership to transfer the ownership of an Open Transport provider (eg an endpoint) between Open Transport clients. In this example, an endpoint is transferred between a shared library and an application that calls that shared library. The code from this sample is featured in the latest release (v1.2) of the book “Inside Macintosh: Open Transport”.
Packing List
The package contains the following items items:
• TransferProvider-PPC.µ — A project to build the PPC version.
• TransferProvider — A compiled version of the above.
• TransferProvider.c — Source code for the application.
• ProviderFactory-PPC.µ — A shared library that creates endpoints for the application.
• ProviderFactory-PPC.µ.exp — An export file for the above.
• ProviderFactory — A compiled version of the above.
• ProviderFactory.h — Interface to the provider factory shared library.
• ProviderFactory.c — Source code for the provider factory shared library.
Sample Requirements
I tested this code with OT 1.2 running under Mac OS 8 on PPC. The code should run just fine with OT 1.1.1 or newer. I do not support this code on OT versions prior to 1.1.1.
The technique illustrated by this sample works just fine on 68K (using a CFM-68K shared library, an ASLM shared library, or a 68K code resource), but it was much easier to build and test using CFM-PPC.
Theory of Operation
The sample contains two projects. The first, “ProviderFactory-PPC.µ”, builds a shared library, “ProviderFactory”, that contains three exported routines. Two of the routines are initialisation and termination routines, the third will create an endpoint on behalf of the client calling the library.
The second project, “TransferProvider-PPC.µ”, is an application that acts as a client of the above shared library. When you run the application, it initialises the “ProviderFactory” library and then calls it to create an endpoint. It then uses OTTransferProviderOwnership to inform OT that the endpoint is now owned by the application, not the shared library.
Running the Sample
To run the sample, simply double click the application and read the output on the console window.
Building the Sample
The sample was built using the Metrowerks CodeWarrior 11 environment and the Open Transport 1.1.1 SDK interfaces and libraries.
To rebuild the sample, first open each project and change the “LatestInterfaces” and “LatestLibraries” access paths to point to the interfaces and libraries from the OT 1.1.1 (or newer) SDK. Then choose Make from the Project menu. Because ProviderFactory is a shared library, it does not matter which order you build the two projects in.
Credits and Version History
If you find any problems with this sample, mail <DevSupport@apple.com> with “Attn: Quinn” as the first line of your mail and I’ll try to fix them up.